package con.shopping.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author ：河神
 * @date ：Created in 2022/2/14 8:33 下午
 */
public class Shopping {

    private Map<GoodDP,Integer> goodsMap;

    public Shopping() {
        goodsMap = new HashMap<>();
    }

    public Map<GoodDP,Integer> getGoodsMap() {
        return goodsMap;
    }

    public void addGoods(GoodDP goods,Integer num){
        goodsMap.merge(goods, num, Integer::sum);
    }

    public void delGoods(GoodDP goods,Integer num){
        goodsMap.merge(goods, num, (a, b) -> b - a);
    }

    public double countMoney(){
        double count = 0;
        Set<Map.Entry<GoodDP, Integer>> entries = goodsMap.entrySet();
        for (Map.Entry<GoodDP, Integer> entry : entries) {
            GoodDP good = entry.getKey();
            Integer num = entry.getValue();
            count = good.getPrice(num)+count;
        }
        return count;
    }

}
